package com.cn.kabalifeuser.ui.order.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.order.bean.OrderExpresBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/10/10.
 * function:
 */
public class IExpressPresenter extends BasePresenter<IExpressView> {

    public void onOrderExpresData(String token, int id) {
        OkGo.<OrderExpresBean>get(Api.API_ORDER_LOGISTICS)
                .params("id", id)
                .headers("token", token)
                .execute(new CacheCallBack<OrderExpresBean>() {
                    @Override
                    public void onSuccess(Response<OrderExpresBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.d("物流信息:" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onOrderExpresSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());

                    }
                });
    }
}
